/**
 * class name: isplit,
 * copyright: maximus zhang,
 * License: MIT-LICENSE,
 * contact: maximus.zhang@gmail.com,
 * required-js: http://jsease.googlecode.com/svn/trunk/hc.js,
 * update: http://jsease.googlecode.com/svn/trunk/isplit.js
 *
 */
function isplit(){
    var A = arguments,
        _ = this;
    _ = ext( _, ext( {
        id : 'split'+ now(3),
        elem : '',
        /* splitercolor : '#abf', */
        width : 200,
        minWidth : 150,
        defWidth : 200,
        maxWidth : 400,
        content : '',
        data : ''
        }, A[0] ) );

    _.uitype = 'isplit';

    _.elem = $(_.elem) || me.body;

    _.reset = function(elem){
        if ( elem && elem.nodeType ) {
            _.elem = elem;
        }

        if ( !_.elem.hasChildNodes() ) {
            _.elem.appendChild(_.$);
        }

        _.setContdata();

        _.width = _.defWidth;
        _.togg(true);

    return _;
    };

    _.setContdata = function () {
        if ( typeof _.data=='function' ) {
            _.xdata = _.data.apply(_.maindata, [_.maindata]);
            if ( typeof _.xdata=='string' ) {
                _.maindata.innerHTML = _.xdata;
            }
        } else if ( typeof _.data=='string' ) {
            _.maindata.innerHTML = _.data;
        } else if ( _.data.nodeType ) {
            _.maindata.empty().appendChild(_.data);
        }

        if ( typeof _.content=='function' ) {
            _.xcont = _.content.apply(_.cont, [_.cont]);
            if ( typeof _.xcont=='string' ) {
                _.cont.innerHTML = _.xcont;
            }
        } else if ( typeof _.content=='string' ) {
            _.cont.innerHTML = _.content;
        } else if ( _.content.nodeType ) {
            _.cont.empty().appendChild(_.content);
        }

    return _;
    };

    _.resizeto = function(w){
        if ( w>=_.minWidth && w<=_.maxWidth ) {
            _.width = w;
            _.togg(true);
        }
    return _;
    };

    _.stop = function(){
        try {
            unbind(me, 'mousemove', _.resize);
            unbind(me, 'mouseup', _.stop);

            if ( $$.msie ) {
                me.onselectstart = function(){;};
            }
        } catch (e) {}
    };

    _.resize = function(ev){
        window.getSelection && window.getSelection().removeAllRanges();
        var ev = evt(ev);
        _.width = ev.X-_.zx<_.minWidth ? _.minWidth : ev.X-_.zx>_.maxWidth ? _.maxWidth : ev.X-_.zx;
        _.togg(true);
    return _;
    };

    _.toresize = function(ev){
        if ( $$.msie ) {
            me.onselectstart = function(){
                me.selection.empty();
                event.returnValue = false;
            };
        }
        window.getSelection && window.getSelection().removeAllRanges();

        var ev = evt(ev);
        _.zx = ev.X-_.width;

        bind(me, 'mousemove', _.resize);
        bind(me, 'mouseup', _.stop);

    return _;
    };

    _.togg = function(f){
        if ( f ) {
            _.cont.style.width = _.width +'px';
            _.cont.style.display = '';
            _.spliter.style.left = _.width +'px';
            _.maindata.style.marginLeft = (_.width+10) +'px';
        } else {
            _.cont.style.display = 'none';
            _.spliter.style.left = 0;
            _.maindata.style.marginLeft = '10px';
        }

    return _;
    };

    _.init = function(){
        _.defWidth = _.width;

        _.$ = elm('div').setClass('isplit').appendTo(_.elem);
        _.$.id = _.id = !$(_.id) ? _.id : 'isplit_'+ _.id;

        _.main = elm('div').setClass('main').appendTo(_.$);
        _.main.id = _.id +'_main';

        _.spliter = elm('div').setClass('spliter').attr('unselectable','on').appendTo(_.$);
        _.spliter.style.cssText = 'left:'+ _.width +'px;';

        _.maindata = elm('div').setClass('data').appendTo(_.main);
        _.maindata.id = _.id +'_data';

        _.cont = elm('div').setClass('content').appendTo(_.$);
        _.cont.id = _.id +'_content';

        _.spliter.ondblclick = function(){
            _.togg( _.spliter.offsetLeft<_.width );
            window.getSelection && window.getSelection().removeAllRanges();
        };

        bind(_.spliter, 'mousedown', _.toresize);

        _.setContdata();

    return _;
    };

}